<extend name="public@base"/>
<block name="seo">
    <title>填写核对订单</title>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <style>
        .table-with-head thead {
            background: #eee;
        }

        .table-with-head {
            border: 1px solid #ddd;
        }
    </style>
</block>
<block name="main">
    <div class="container">
        <div class="row" style="margin-bottom: 10px;margin-top: 10px;">
            <div class="col-md-3">
            </div>
            <div class="col-md-9">
                <div class="btn-group btn-group-justified pull-right">
                    <a class="btn btn-primary" role="button">1.我的购物车</a>
                    <a class="btn btn-success" role="button">2.填写核对订单</a>
                    <a class="btn btn-primary" role="button">3.成功提交订单</a>
                </div>
            </div>
        </div>

        <div>
            <form class="form js-ajax-form" action="{:url('order/Cart/submit')}" method="post" id="submit-cart-form">

                <table class="table table-with-head">
                    <thead>
                    <tr>
                        <th colspan="7">
                            收货人信息<a href="javascript:;" id="open-useraddress-dialog">[使用新地址]</a>
                        </th>
                    </tr>
                    </thead>
                    <tbody>
                    <foreach name="user_addresses" item="vo">
                        <tr>
                            <td width="30">
                                <notempty name="vo.is_default">
                                    <input type="radio" checked="checked" name="user_address_id" value="{$vo.id}">
                                    <else/>
                                    <input type="radio" name="user_address_id" value="{$vo.id}">
                                </notempty>
                            </td>
                            <td>{$vo.alias}</td>
                            <td>收货人:{$vo.consignee}</td>
                            <td>
                                {$areas[$vo['province']]}{$areas[$vo['city']]|default=''}{$areas[$vo['district']]|default=''}
                                {$vo.address}
                            </td>
                            <td>电话：{$vo.mobile} {$vo.mobile2}</td>
                            <td>
                                <notempty name="vo.is_default">
                                    默认地址
                                    <else/>
                                    <a class="js-ajax-dialog-btn"
                                       href="{:url('order/UserAddress/setDefault',array('id'=>$vo['id']))}"
                                       data-msg="您确定将这个地址设为默认地址吗？">默认地址</a>
                                </notempty>
                            </td>
                            <td>
                                <a class="js-open-edit-dialog-btn"
                                   href="{:url('order/UserAddress/editDialog',array('id'=>$vo['id']))}">编辑</a>
                                <a class="js-ajax-delete" data-msg="您确认删除吗？"
                                   href="{:url('order/UserAddress/delete',array('id'=>$vo['id']))}">删除</a>
                            </td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
                <table class="table table-with-head">
                    <thead>
                    <tr>
                        <th>
                            发票信息(请谨慎选择发票抬头，订单出库后不能修改)
                        </th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td>
                            <div class="col-md-12">
                                <input type="hidden" name="invoice_id" id="js-invoice-id"
                                       value="{$invoice_info.id|default=''}"/>
                                <span class="js-invoice-title">
                                <empty name="invoice_info">
                                    不开发票
                                    <else/>
                                    <eq name="invoice_info.type" value="2">
                                        普通发票（纸质） {$invoice_info.title}
                                    </eq>
                                    <eq name="invoice_info.type" value="3">
                                        增值税专用发票（纸质） {$invoice_info.title}
                                    </eq>
                                </empty>
                            </span>
                                <a href="javascript:;" id="js-edit-invoice-dialog">修改</a>
                                <a href="javascript:;" id="js-cancel-invoice">取消</a>
                            </div>
                        </td>
                    </tr>
                    </tbody>
                </table>

                <h4 class="text-center">
                    您购买的商品
                </h4>
                <table class="table table-bordered table-centered" style="margin-bottom: 5px;">
                    <thead>
                    <tr>
                        <th>商品</th>
                        <th></th>
                        <th>价格</th>
                        <th>数量</th>
                        <th>小计</th>
                    </tr>
                    </thead>
                    <tbody>
                    <foreach name="shops_goods" item="goods" key="shop_id">
                        <tr>
                            <td colspan="5">
                                店铺:
                                <empty name="shop_id">
                                    自营
                                    <else/>
                                    {$shops[$shop_id]['name']}
                                </empty>
                            </td>
                        </tr>
                        <foreach name="goods" item="vo">
                            <tr>
                                <td>{$vo.goods_name}</td>
                                <td>{:str_replace(";\\n",'<br>',$vo.goods_spec)}</td>
                                <td>{$vo.goods_price}</td>
                                <td>{$vo.goods_quantity}</td>
                                <td>{:number_format(round($vo.goods_price * $vo.goods_quantity,2),2)}</td>
                            </tr>
                        </foreach>
                        <tr>
                            <td colspan="5">
                                备注:&nbsp;
                                <input class="form-control" name="user_note[{$shop_id}]"
                                       style="display: inline-block;width: 350px;">
                                &nbsp; 如果你有特别的需求，可以写这里
                            </td>
                        </tr>
                    </foreach>
                    <!-- <tr>
                        <td colspan="2"></td>
                        <td align="right">运费：</td>
                        <td width="110">￥0.00</td>
                    </tr> -->

                    </tbody>
                </table>
                <div class="text-right" style="border: #ddd 1px solid;padding: 20px;margin: 10px 0;">
                    合计：<em>￥<b class="total-amount-text">{:number_format($total_amount,2)}</b></em>
                </div>
                <div class="pull-right">
                    <button class="btn btn-danger js-ajax-submit submit-order-btn" data-wait="3000">提交订单</button>
                </div>
                <div class="clearfix"></div>
            </form>
        </div>

    </div>
</block>
<block name="script">
    <script>
        Wind.css('artDialog');
        Wind.use("artDialog", "iframeTools", function () {
            $('#open-useraddress-dialog').on('click', function () {
                openIframeLayer("{:url('order/UserAddress/addDialog')}", '使用新地址', {
                    area: ['700px', '90%'],
                    btn: ['确定', '取消'],
                    yes: function (index, layero) {
                        console.log(layero);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        iframeWin.submit();
                        //layer.close(index); //如果设定了yes回调，需进行手工关闭
                    }
                });
                return false;
            });

            $('#js-edit-invoice-dialog').on('click', function () {
                openIframeLayer("{:url('order/UserInvoice/editDialog')}", '修改发票信息', {
                    area: ['700px', '90%'],
                    btn: ['确定', '取消'],
                    yes: function (index, layero) {
                        console.log(layero);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        iframeWin.submit(function () {
                            alert('dd');
                        });
                        //layer.close(index); //如果设定了yes回调，需进行手工关闭
                    }
                });
                return false;
            });

            $('.js-open-edit-dialog-btn').on('click', function () {
                openIframeLayer($(this).attr('href'), '使用新地址', {
                    area: ['700px', '90%'],
                    btn: ['确定', '取消'],
                    yes: function (index, layero) {
                        console.log(layero);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        iframeWin.submit();
                        //layer.close(index); //如果设定了yes回调，需进行手工关闭
                    }
                });
                return false;
            });
        });

        function getNewAddress(data) {

            reloadPage(window);
        }

        var $submitOrderBtn = $('.submit-order-btn');

        $("[name='group_id']").change(function () {

            var $this = $(this);
            var groupId = parseInt($this.val());
            if (groupId > 0) {
                $submitOrderBtn.data('action', "{:url('lab/Cart/submit')}");
            } else {
                $submitOrderBtn.data('action', "{:url('order/Cart/submit')}");
            }
        });

        $('#js-cancel-invoice').click(function () {
            $('#js-invoice-id').val(0);
            $('.js-invoice-title').text('不开票');
        });
    </script>
</block>
<block name="footer"></block>